<!--
 * @Date: 2024-12-13 10:20:04
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-02-18 10:49:25
 * @Description: 分类指标组件
-->
<template>
  <div class="input-series">
    <el-button :plain="!existContent"
      round type="primary" size="small" @click="handleOpen">编辑</el-button>
  </div>
</template>

<script setup>
import { watch } from 'vue';
import { isEmpty } from '@hp/utils/data.js'

import { callComp } from '@/plugins/call-comp/CallCompPlugins.jsx'
import KindConfigDialog from './components/KindConfigDialog.vue'

const emits = defineEmits(['update:modelValue'])

const props = defineProps({
  row: { type: Object },
  schema: { type: Object },
  config: { type: Object },
  modelValue: {},
  checkedNode: { type: Object },
})

const kindConfig = ref([])
const existContent = computed(() => {
  return props.modelValue
})
const handleOpen = () => {
  const dialogAttrs = {
    ...props,
    pData: props.row,
    modelState: kindConfig.value,
  }
  delete dialogAttrs.modelValue
  callComp.open(KindConfigDialog, {
    ...dialogAttrs,
    onConfirm: (res) => {
      emits('update:modelValue', res)
    }
  })
}

watch(
  () => props.modelValue,
  (nv) => {
    if (isEmpty(nv)) {
      kindConfig.value = []
    } else {
      kindConfig.value = JSON.parse(JSON.stringify(nv))
    }
  },
  { deep: true, immediate: true }
)

</script>

<style lang="scss" scoped>
.input-series {
  &-line {
    display: flex;
    align-items: center;
    .line-item {
      display: flex;
      margin-right: 10px;
      &:last-child {
        margin-right: 0;
      }
    }
  }
}
</style>